<template>
	<view class="tag-introduction">
		<div class="tag-introduction-paragraph" v-for="(paragraph, i) in paragraphs" :key="i">{{paragraph}}</div>
		<div v-for="link in data.links" :key="link.url"> {{link.text}} <a :href="link.url">{{link.url}}</a></div>
	</view>
</template>

<script lang="ts">
	import {
		ArticleTag
	} from "@/models/tags"

	export default {
		data() {
			return {
				tag: "",
				data: {} as ArticleTag
			}
		},
		computed: {
			paragraphs() {
				if (this.data.description == null) {
					return []
				}
				return this.data.description.split("\n")
			}
		},
		onLoad(options) {
			this.tag = options.tag
			uni.request({
				url: `static/data/tags/${this.tag}.json`,
				method: "GET",
				success: (res) => {
					console.log(res); //输出
					this.data = res.data as ArticleTag
				}
			});
			console.log('options', options)

			uni.setNavigationBarTitle({
				title: `Tag #${this.tag}`
			})
		}
	}
</script>

<style scoped>
	.tag-introduction {
		padding: 12px;
		box-sizing: border-box;
	}

	.tag-introduction :first-child {
		margin-top: 0px;
	}

	.tag-introduction-paragraph {
		margin-top: 12px;
	}
</style>
